package ch.app.controller;

import java.io.Serializable;
import java.util.List;

import javax.annotation.Resource;
import ch.app.redis.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import ch.app.dao.GetCashDao;
import ch.app.dao.UserDao;
import ch.app.entity.GetCash;
import ch.app.entity.UserDepartment;
import ch.app.entity.UserEntity;
import ch.app.service.impl.RedisServiceImpl;

/**
 * 
 * @author Yin Yong Gang
 * Date:
 * Description:
 */

@RestController
@RequestMapping("/chaohi")
public class PayInfoController {

	@Resource
	private UserDao userDao;
	
	@Resource
	private GetCashDao getCashDao;
	
	@Resource
	private RedisUtil redisUtil;
	
	@Autowired
	private RedisTemplate redisTemplate;
	
	@Autowired     
	private RedisServiceImpl redisServiceImpl;
	
	@RequestMapping("/pay")
	public List<UserEntity> findAll() {
		List<UserEntity> userlist= userDao.findAll();
		System.out.println(userlist.get(0).getNickName());
		return userlist;
	}
	
	@RequestMapping(value = "/pay2")
	public UserDepartment findUserInfo(String userName) {
		UserDepartment user= userDao.findUserInfo(userName);
		System.out.println(userName + " : " + user.getDepartment());
		return user;
	}
	
    //设置redis中的key和value  
    @RequestMapping("/add")  
    public String setRedis(String id,String name){
        redisServiceImpl.set(id, name);
        return "redis设置成功"+"id="+id+" name="+name;
    }  
    
    //设置redis中的key和value  
    @RequestMapping("/get")  
    public String getRedis(String id){
    	String key = "james-2";
    	String value = "123";
    	boolean name = redisServiceImpl.set(key, value);
    	String name2 = redisUtil.get("name");
    	redisUtil.set("key1", "value1");
    	
    	ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue();
 	    operations.set(key, value);
 	    
    	System.out.println(name2);
        return "success";
    }  
    
  //设置redis中的key和value  
    @RequestMapping("/get2")  
    public void getCashDao(){
    	List<GetCash> cash = getCashDao.findAll();
    	
        System.out.println(cash.get(0).getUnion_id());
    }  
}
